// Chat Program for PCMod (CLIENT)

PROG.PName = "WebBrowse"
PROG.Author = "[GU]|ZLC|thomasfn"

PROG.NiceName = "WebBrowse V1.0"

PCMod.WB = {}

function PROG:BuildWindow( WindowName, Desktop, Object )
	// Here we build the derma window.
	// Note the Desktop string is needed for every operation involving derma.
	
	if (WindowName == "Main") then		
	
		// Add the HTML Box area
		local pn = vgui.Create( "HTML" )
		pn:SetParent( Object )
		pn:SetPos( 5, 50 )
		pn:SetSize( Object:GetWide()-10, Object:GetTall()-55 )
		PCMod.WB.Page = pn
		
		// Add the URL textbox and buttons
		DInterface:AddLabel( "lblInfo", Desktop, "URL:", 5, 25 )
		PCMod.WB.URL = DInterface:AddTextbox( "txtURL", Desktop, "", 25, 25, Object:GetWide()-100, 20 )
		DInterface:AddButton( "btnGo", Desktop, "Go", Object:GetWide()-60, 25, 60, 20, function()
			if (PCMod.WB.URL) then
				PCMod.WB:Navigate( PCMod.WB.URL:GetValue() )
			end
		end )
		
		self.Desktop = Desktop
		
	end
	
	// Add a quit button
	DInterface:AddButton( "btnQuit", Desktop, "X", Object:GetWide()-20, 0, 20, 20, function() SendCommand( "quit" ); end )
end

function PROG:ClearWindow( Desktop )
	// Here we destroy EVERY derma control that MIGHT exist.
	
	DInterface:RemoveLabel( "lblInfo", Desktop )
	DInterface:RemoveButton( "btnGo", Desktop )
	
	if (PCMod.WB.URL) then
		PCMod.WB.URL:Remove()
		PCMod.WB.URL = nil
	end
	
	if (PCMod.WB.Page) then
		PCMod.WB.Page:Remove()
		PCMod.WB.Page = nil
	end
	
	DInterface:RemoveButton( "btnQuit", Desktop )
end

// Data[1] = Tag
// Data[2] = Content
function PROG:DataRecieved( Desktop, Data )
	// The server has sent us some data
end

// Custom Functions
function PCMod.WB:Navigate( url )
	Msg( "Navigating to '" .. url .. "'!\n" )
	if (!PCMod.WB.Page) then return end
	PCMod.WB.Page:OpenURL( url )
end

function PROG:Paint( x, y, w, h )
	--draw.RoundedBox( 4, x+(w*0.05), y+(h*0.1), w*0.9, h*0.75, Color( 255, 255, 255, 200 ) )
end